package org.darcy.service.impl;

import org.darcy.dao.BizArticleTagsMapper;
import org.darcy.entity.BizArticleTags;
import org.darcy.framework.generic.GenericServiceImpl;
import org.darcy.service.BizArticleTagsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

/**
 * 文章标签
 */
@Service
public class BizArticleTagsServiceImpl extends GenericServiceImpl<BizArticleTags> implements BizArticleTagsService {

	@Autowired
	private BizArticleTagsMapper bizArticleTagsMapper;

	/**
	 * 通过文章id删除文章-标签关联数据
	 *
	 * @param articleId
	 * @return
	 */
	@Override
	public int removeByArticleId(Long articleId) {
		// 删除 文章-标签关联数据
		QueryWrapper<BizArticleTags> q = new QueryWrapper<BizArticleTags>();
		q.eq("article_id", articleId);
		return bizArticleTagsMapper.delete(q);
	}

	/**
	 * 批量添加
	 *
	 * @param tagIds
	 * @param articleId
	 */
	@Override
	public void insertList(Long[] tagIds, Long articleId) {
		if (tagIds == null || tagIds.length == 0) {
			return;
		}
		BizArticleTags articleTags = null;
		for (Long tagId : tagIds) {
			articleTags = new BizArticleTags();
			articleTags.setTagId(tagId);
			articleTags.setArticleId(articleId);
			this.insert(articleTags);
		}
	}


}
